package com.example.demo.mapper;

import com.example.demo.entity.GoodsOrders;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Mr.Yang
 * @since 2024-05-31
 */
@Mapper
public interface GoodsOrdersMapper extends BaseMapper<GoodsOrders> {

    /**
     * 根据用户id查询订单
     * @param userId
     * @return
     */
    @Select("select * from goods_orders where user_id = #{userId}")
    List<GoodsOrders> selectByUserId(Integer userId);

    /**
     * 更改订单状态
     * @param goods
     * @return
     */
    @Update("update goods_orders set order_status = #{orderStatus},update_time = NOW() where gorder_id = #{gorderId}")
    Boolean updateOrderStatusById(GoodsOrders goods);

    /**
     * 根据id查询订单
     * @param id
     * @return
     */
    @Select("select * from goods_orders where gorder_id = #{id}")
    GoodsOrders selectById(Integer id);

    /**
     * 根据id删除订单
     * @param id
     * @return
     */
    @Delete("delete from goods_orders where gorder_id = #{id}")
    Boolean deleteByGorderId(Integer id);

    @Select("select * from goods_orders")
    List<GoodsOrders> selectAllOrder();
}
